// pages/goodList/goodList.js
import res from "../../request/request.js"

Page({

  /**
   * 页面的初始数据
   */
  data: {
goodList:[],
pagenum:1,
pagesize:10,
// isnow若为true则在综合界面，若false则价格页面
isnow:true,
//id
id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
this.getGoodList(options.option)
this.setData({
  id:options.option
})
  },
  getGoodList(keyWord) {
    res.request({
      url: "/goods/search",
    data:{
      cid:keyWord,
      pagenum:this.data.pagenum,
      pagesize:this.data.pagesize
    }
    }).then(data => {
      this.setData({
        goodList:data,
        total:data.total
      })
    })
  },
  getGoodList2(keyWord) {
    res.request({
      url: "/goods/search",
    data:{
      cid:keyWord,
      pagenum:this.data.pagenum,
      pagesize:this.data.total
    }
    }).then(data => {
      let goodList = data
      let goodListgood = data.goods
goodListgood.sort((a,b)=>{return a.goods_price-b.goods_price})
this.setData({
  isnow:false,
  goodList:goodList,
  goodListgood:goodList.goods,
  pagesize:goodList.total
})
    })
  },
  go_detail(e){
wx.navigateTo({
  url: '../detail/detail?option='+e.currentTarget.dataset.id,
})
  },
  getzonghe(){
    this.getGoodList(this.data.id)
    this.setData({
      isnow:true
    })
  },
  // 价格从低到高排序
  getprice(){
this.getGoodList2(this.data.id)

  },
  jump(){
wx.navigateTo({
  url: '../serch/serch',
})
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
let isnow =this.data.isnow
if(isnow){
  this.getGoodList(this.data.id)
  this.setData({
    pagenum:1,
  pagesize:this.data.pagesize+10
  })
}else{
  
}

  },

  
})